﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Comp376A2_9609695
{
    /// <summary>
    /// A Score class to make drawing right-aligned digits easy
    /// </summary>
    public class Score : Drawable
    {
        public int value;
        public Vector2 position;
        private SpriteSheet numberSheet;

        public Score(SpriteSheet sheet)
        {
            numberSheet = sheet;
            value = 0;
            position = new Vector2();
        }

        public Texture2D getImage()
        {
            return numberSheet.image;
        }

        public void draw(SpriteBatch renderer)
        {
            // Start with the rightmost digit, then drawn each one to the left
            int digits;
            if (value > 0)
                digits = (int)Math.Floor(Math.Log10(value)) + 1;
            else 
                digits = 1;
            for (int i = 0; i < digits; i++)
            {
                int digit = value;digit = value / (int)Math.Pow(10, i);
                digit = digit % 10;
                Rectangle drawPos = new Rectangle((int)position.X - 8 * i, (int)position.Y, 8, 8); 
                renderer.Draw(numberSheet.image, drawPos, numberSheet.getSprite(digit), Color.White);
            }
        }
    }
}
